package com.example.lwj.FragmentDemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
=======
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
=======
import com.example.lwj.BaseDemo.BaseDate;
import com.example.lwj.utils.URLUtils;
>>>>>>> name
>>>>>>> name
import com.example.lwj.view.XListView;
import com.example.lwj.zhangtianchengnews.R;

import java.util.ArrayList;

/**
 * Created by lwj on 2016/11/1.
 */
public class MainFragment extends Fragment implements XListView.IXListViewListener{

    private ArrayList<String> datalist;
    private XListView xv;
    private ArrayAdapter<String> stringArrayAdapter;
    private int startIndex=0;
    @Nullable
    @Override


    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        datalist = new ArrayList<String>();
        View view = inflater.inflate(R.layout.list_item, null);
        //找到控件
        xv = (XListView) view.findViewById(R.id.xlistView);
        xv.setPullLoadEnable(true);

<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        //初始化数据
        init();
=======
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        //初始化数据
        init();
=======

>>>>>>> name
>>>>>>> name
        stringArrayAdapter = new ArrayAdapter<String>(getContext(),android.R.layout.simple_expandable_list_item_1,datalist);
        xv.setAdapter(stringArrayAdapter);
        xv.setXListViewListener(this);
        return view;
    }

<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
=======
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
>>>>>>> name
    private void init() {
        for (int i=startIndex;i<startIndex+20;i++){
            datalist.add("I am " + i + "item");
        }


    }
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
=======
=======
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        String category = getArguments().getString("category");

        BaseDate baseData = new BaseDate() {
            @Override
            public void setResultData(String data) {
                showData(data);
            }



            @Override
            protected void setFailResult(int error_Net) {

            }
        };
        baseData.getData(URLUtils.URL_CATEGROY_PATH + category, BaseDate.LONGTIME);
    }
    private void showData(String data) {


    }

>>>>>>> name
>>>>>>> name
    private void onLoad() {
        xv.stopRefresh();
        xv.stopLoadMore();
        xv.setRefreshTime("刚刚");
    }

    public static Fragment getData(String title) {
        MainFragment f1 = new MainFragment();
        Bundle bundle = new Bundle();
        bundle.putString("name", title);
        f1.setArguments(bundle);
        return f1;
    }

    @Override
    public void onRefresh() {
        datalist.clear();
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        init();
=======
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        init();
=======
>>>>>>> name
>>>>>>> name
        onLoad();
        stringArrayAdapter.notifyDataSetChanged();
    }

    @Override
    public void onLoadMore() {
        startIndex=startIndex+20;
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        init();
=======
<<<<<<< 402333128f97e730bcec37a5518c69dc79bda292
        init();
=======
>>>>>>> name
>>>>>>> name
        onLoad();
        stringArrayAdapter.notifyDataSetChanged();

    }
}
